package framework.util;

import java.io.File;
import java.util.Objects;

/**
 * @author 马洁
 * @date 2020/3/11 - 19:56
 */
public class FileUtil {
    public static final char WINDOWS_SLASH = '\\';
    public static final char UNIX_SLASH = '/';
    private static FileUtil fileUtil = new FileUtil();

    public static String getUnixStr(String str) {
        return fileUtil.isWindowsOs() ?
                fileUtil.convertToUnixRules(str) :
                str;
    }

    private boolean isWindowsOs() {
        return Objects.equals(WINDOWS_SLASH, File.separatorChar);
    }

    private String convertToWindowsRules(String filePath) {
        return filePath.replace(UNIX_SLASH, WINDOWS_SLASH);
    }

    private String convertToUnixRules(String filePath) {
        return filePath.replace(WINDOWS_SLASH, UNIX_SLASH);
    }
}
